package com.cst.quartz定时任务;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class App {
    public static void main(String[] args) throws SchedulerException {
        /*创建JobDetail实例，并与HelloJob绑定；Job的名字是myjob，隶属于job_group组*/
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
                .withIdentity("myjob", "job_group")
                .build();

        /*创建Trriger实例，指定Job每隔3秒钟执行一次*/
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("mytrigger", "trigger_group")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(3)
                        .repeatForever())
                .build();

        /*创建SchedulerFactory实例，把jobDetail与trigger绑定在一起*/
        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.start();
        scheduler.scheduleJob(jobDetail, trigger);

    }
}